﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace JsonComaprer.NET
{
    /// <summary>
    /// 对比json 的对比器的 配置信息
    /// </summary>
    public class JsonComparerSetting
    {
        public JsonComparerSetting()
        {
            this.EquesMappings = new Dictionary<string, EqualsMappingSetting>();
        }

        /// 对比时， 某个key所对应的 value, 左右都可以视为相等的 映射关系. 如果为空，则默认按照字符串 相等判断
        /// EqualsMapping.LeftValues之中的任何一个值， 都可以和  EqualsMapping.RightValues 相等.
        /// </summary>
        public Dictionary<String, EqualsMappingSetting> EquesMappings { get; set; }
    }

    public class EqualsMappingSetting
    {
        public EqualsMappingSetting()
        {
            this.IgnoreCase = true;
            this.LeftValues = null;
            this.RightValues = null;
        }
        /// <summary>
        /// 对比时， value 是否忽略大小写 配置 使用 优先级高于 EquesMappings
        /// </summary>
        public Boolean IgnoreCase { get; set; }
      
        public List<String> LeftValues {  get;  set; }
        public List<String> RightValues {  get;  set; }

        public bool CanUseEquesMappings()
        {
            if (this.LeftValues != null && this.LeftValues.Count > 0 && this.RightValues != null && this.RightValues.Count > 0)
            {
                return true;
            }
            return false;
        }

        public bool HasLeftValuesContains(String value)
        {
            Boolean flag = false;
            if (this.LeftValues != null)
            {
                foreach (var item in this.LeftValues)
                {
                    flag = String.Compare(value, item, this.IgnoreCase) == 0;
                    if (flag)
                    {
                        break;
                    }
                }
            }

            return flag;
        }

        public bool HasRightValuesContains(String value)
        {
            Boolean flag = false;
            if (this.RightValues != null)
            {
                foreach (var item in this.RightValues)
                {
                    flag = String.Compare(value, item, this.IgnoreCase) == 0;
                    if (flag)
                    {
                        break;
                    }
                }
            }

            return flag;
        }

        public bool IsTheSameValues(String str1, String str2)
        {
            return String.Compare(str1, str2, this.IgnoreCase) == 0;
        }
    }

}